package gestionFichiersEJBImpl;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.ejb.Stateless;

/**
 * Session Bean implementation class GestionFichiersEJB
 */
@Stateless(mappedName = "GestionFichiersEJB")
public class GestionFichiersEJB implements GestionFichiersEJBRemote{

	
	//@PersistenceContext(unitName="serveurtravailcollaboratif")
	//EntityManager em;
	
    /**
     * Default constructor. 
     */
    public GestionFichiersEJB() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public boolean uploadAFile(byte[] contenuFichier, byte[] name) {
		// TODO Auto-generated method stub
		
		System.out.println("Dans l'EJB");
		
		boolean reussite = false;
		
		String nomFichier = new String(name);
		
		File fichierRecu = new File("/opt/pad/NicolasScheubel/Fichiers/"+nomFichier);
		
		if(fichierRecu != null){
			
			reussite = true;
			
		}
		
		try {
			
			FileOutputStream fileOut = new FileOutputStream(fichierRecu);
			fileOut.write(contenuFichier);
			fileOut.close();
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	/*	if(em.isOpen()==false){
			
			System.out.println("Pas encore de BDD");
			
		}*/

		
		System.out.println("Fichier chargé !!!");
		
		return reussite;
		
	}

	@Override
	public String downloadAFile(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean saveAFile(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean createDirectory(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean createFile(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteFile(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteDirectory(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean editFile(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean rename(String name, String newName) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean chmod(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean compress(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}

}
